package com.itheima.net;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {
    public static void main(String[] args) throws IOException {
        ExecutorService pool = new ThreadPoolExecutor(
                30,
                34,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
        ServerSocket ss = new ServerSocket(10086);
        System.out.println("服务器已启动，等待客户端连接...");
        while (true){
            Socket socket = ss.accept();
            System.out.println("一个客户端连接了"+socket.getInetAddress().getHostAddress());
            pool.execute(new chat(socket));
        }
    }
}
